package com.bestom.waterquality.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author shulman
 */
public class DbHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "data.db";
    //预警记录表
    public static final String WARNING_NAME = "warning_record";
    //实时上报MQtt记录表
    public static final String REAL_NAME = "real_record";

    //平均值记录表
    public static final String ORP_NAME = "orp_avg";
    public static final String PH_NAME = "ph_avg";
    public static final String VCP_NAME = "vcp_avg";

    //实时记录数据表
    public static final String ORP_Record_NAME = "orp_record";
    public static final String PH_Record_NAME = "ph_record";
    public static final String VCP_Record_NAME = "vcp_record";

    private static final int DATABASE_VERSION = 1;

    public DbHelper(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + WARNING_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "warning_data varchar," +
                "image_path varchar" +
                ") ");

        //sqLiteDatabase.execSQL("insert into warning_record(time,warning_data,image_path) values(?,?,?)", new String[] { "2021-06-10 12:13:14", "50", "1622809642627.jpg" });
        //sqLiteDatabase.execSQL("insert into warning_record(time,warning_data,image_path) values(?,?,?)", new String[] { "2021-06-10 12:13:14", "60", "1622810070780.jpg" });

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + REAL_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "real_vcp varchar," +
                "real_tmp varchar," +
                "image_path varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + ORP_Record_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + PH_Record_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + VCP_Record_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + ORP_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + PH_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + VCP_NAME +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "time varchar," +
                "data varchar" +
                ") ");

        //sqLiteDatabase.execSQL("insert into real_record(time,real_vcp,real_tmp,image_path) values(?,?,?,?)", new String[] { "2021-06-10 12:13:14", "50", "50", "1622809642627.jpg" });
        //sqLiteDatabase.execSQL("insert into real_record(time,real_vcp,real_tmp,image_path) values(?,?,?,?)", new String[] { "2021-06-10 12:13:14", "60", "60", "1622810070780.jpg" });
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
